# -*- encoding: utf-8 -*-
"""
@author: CarpeDiem
@data: 22/9/28
@version: 0.1
@description: 计算表面积
@method: 遍历一下，和周围的元素比较，想法就是补零
"""
import numpy as np

def surfaceArea(grid):
    length = len(grid)
    grid_array = np.array(grid)
    grid_array = np.pad(grid_array, (1, 1), 'constant')
    sum = 0
    for i in range(1, length+1):
        for j in range(1, length+1):
            temp = grid_array[i, j]
            if temp:
                sum += temp * 4 + 2 - min(temp, grid_array[i, j-1]) - min(temp, grid_array[i, j+1]) - min(temp, grid_array[i-1, j]) - min(temp, grid_array[i+1, j])
    return sum

def main():
    arr1 = [[1, 1, 1], [1, 0, 1], [1, 1, 1]]
    arr2 = [[2, 2, 2], [2, 1, 2], [2, 2, 2]]
    print(surfaceArea(arr1))
    print(surfaceArea(arr2))

main()